﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.Entity;
using System.Globalization;
namespace QuanLyPhongGiam
{

    public partial class frmThongKeTongHop : Form
    {
        DateTime BatDau;
        DateTime KetThuc;
        public frmThongKeTongHop(DateTime startDate, DateTime endDate)
        {
            BatDau = startDate;
            KetThuc = endDate;
            InitializeComponent();
        }
        private void Form2_Load(object sender, EventArgs e)
        {
            List<ThongKe> lstBiCan = LoadThongKe();
            LoadListBiCan(lstBiCan);
        }
        private List<ThongKe> LoadThongKe()
        {
            int rs = -1;
            using (var ctx = new QuanLySinhVienEntities())
            {
                var idParam = new SqlParameter("@StartDate", BatDau);
                var idParamEndDate = new SqlParameter("@EndDate", KetThuc);

                ThongKeTriger t = new ThongKeTriger();
                t.DateStart = BatDau;
                t.DateEnd = KetThuc;
                ctx.ThongKeTrigers.Add(t);
                rs = ctx.SaveChanges();
            }
            var result = new List<ThongKe>();
            if (rs > 0)
            {
                using (var ctx = new QuanLySinhVienEntities())
                {
                    result = ctx.ThongKes.OrderByDescending(x => x.TT).ToList();
                }
            }
            return result;
        }
        private void LoadListBiCan(List<ThongKe> lstBiCan)
        {
            foreach (var biCan in lstBiCan)
            {
                ListViewItem item = new ListViewItem(biCan.TT.ToString());
                item.SubItems.Add(biCan.TieuChi.ToString());
                item.SubItems.Add(biCan.TongSo.ToString());
                listView1.Items.Add(item);
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void listView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void listView1_SelectedIndexChanged_1(object sender, EventArgs e)
        {

        }
        private void listView1_Click(object sender, EventArgs e)
        {

        }


        private void button2_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click_1(object sender, EventArgs e)
        {
        }

        private void button3_Click(object sender, EventArgs e)
        {
        }
        private void btnChiTiet_Click(object sender, EventArgs e)
        {
        }

        private void btnLamMoi_Click(object sender, EventArgs e)
        {
        }

        private void btnIn_Click(object sender, EventArgs e)
        {
            frmReporttThongKeTongHop rpt = new frmReporttThongKeTongHop();
            rpt.ShowDialog();
        }

    }
}
